<template>
  <div>
    <el-dialog title="添加管理员" :visible.sync="obj.isshow">
      <el-form :model="form">
        <el-form-item label="所属角色" :label-width="formLabelWidth">
          <el-select v-model="form.roleid" placeholder="请选择所属角色">
            <el-option v-for="item in roleArr" :key="item.id" :label="item.rolename" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="form.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" :label-width="formLabelWidth">
          <el-input
            show-password
            v-model="form.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-switch
            :active-value=1
            :inactive-value=2
            v-model="form.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="adduser">添加</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getAllRole,addOneManager } from "../../../request/api.js";
import { successMsg,faileMsg } from "../../../tools/tools.js";

export default {
  props:['obj'],
  data() {
    return {
      roleArr:[],//所有角色
      form: {
        roleid: "", //所属角色id
        username: "",
        password: "",
        status: 1,
      },
      formLabelWidth:'120px'
    };
  },
  mounted(){
      this.getAllRoleData();
  },
  methods:{
    resetForm(){
        this.form={
        roleid: "", //所属角色id
        username: "",
        password: "",
        status: 1,
      },
      this.obj.isshow = false;
    },
    //添加管理员
    adduser(){
       addOneManager(this.form).then(d=>{
         if(d.data.code == 200){
            successMsg('管理员添加成功');
         }else{
            faileMsg('管理员添加失败')
         }

         this.resetForm();
       }).catch(e=>{})
    },
    //获取所有角色数据：
    getAllRoleData(){  
      getAllRole().then(d=>{
      
        if(d.data.code == 200){
           this.roleArr = d.data.list
        }
       // console.log(this.roleArr,'this.roleArr');
      }).catch(e=>{});
    }
  }
};
</script>

<style>
</style>